import 'package:flutter/material.dart';
import 'package:family_app/src/features/auth/screens/login_screen.dart';
import 'package:family_app/src/features/gallery/screens/gallery_screen.dart';
import 'package:family_app/src/features/finance/screens/finance_screen.dart';
import 'package:family_app/src/features/finance/screens/home_screen.dart';
import 'package:family_app/src/features/finance/screens/accounting_screen.dart';
import 'package:family_app/src/features/finance/screens/stats_screen.dart';
import 'package:family_app/src/features/finance/screens/budget_screen.dart';
import 'package:family_app/src/features/secure_vault/screens/secure_vault_screen.dart';
import 'package:family_app/src/features/calendar/screens/calendar_screen.dart';
import 'package:family_app/src/features/family/screens/family_members_screen.dart';

/// 应用路由管理
class AppRouter {
  // 私有构造函数
  AppRouter._();

  /// 路由名称常量
  static const String splash = '/';
  static const String login = '/login';
  static const String home = '/home';
  static const String gallery = '/gallery';
  static const String finance = '/finance';
  static const String financeHome = '/finance/home';
  static const String accounting = '/finance/accounting';
  static const String stats = '/finance/stats';
  static const String budget = '/finance/budget';
  static const String secureVault = '/secure-vault';
  static const String calendar = '/calendar';
  static const String family = '/family';

  /// 路由表
  static Map<String, WidgetBuilder> get routes => {
        login: (context) => const LoginScreen(),
        gallery: (context) => const GalleryScreen(),
        finance: (context) => const FinanceScreen(),
        financeHome: (context) => const HomeScreen(),
        accounting: (context) => const AccountingScreen(),
        stats: (context) => const StatsScreen(),
        budget: (context) => const BudgetScreen(),
        secureVault: (context) => const SecureVaultScreen(),
        calendar: (context) => const CalendarScreen(),
        family: (context) => const FamilyMembersScreen(),
      };

  /// 路由生成器
  static Route<dynamic> onGenerateRoute(RouteSettings settings) {
    return MaterialPageRoute(
      settings: settings,
      builder: (context) {
        switch (settings.name) {
          // 可以在这里处理需要参数的路由
          default:
            return const Scaffold(
              body: Center(
                child: Text('页面不存在'),
              ),
            );
        }
      },
    );
  }

  /// 未知路由处理
  static Route<dynamic> onUnknownRoute(RouteSettings settings) {
    return MaterialPageRoute(
      builder: (context) => Scaffold(
        appBar: AppBar(title: const Text('页面不存在')),
        body: const Center(child: Text('找不到请求的页面')),
      ),
    );
  }
}
